package com.yogee.topseller.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yogee.topseller.R;
import com.yogee.topseller.bean.RetunContactBean;

import java.util.ArrayList;
import java.util.List;

/**
* 快递公司适配器
* @author hanyu
* created by 2017/7/12 17:50
*/

public class ExpressCompanyAdapter extends RecyclerView.Adapter<ExpressCompanyAdapter.ExpressCompanyViewHolder> {

    private Context mContext;
    OnClickListener mListener;
    private List<RetunContactBean.DisLists> mBean = new ArrayList<>();
    
    public ExpressCompanyAdapter(Context context,OnClickListener listener){
        mContext = context;
        this.mListener = listener;
    }

    public void addData(List<RetunContactBean.DisLists> list){
        this.mBean = list;
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(final ExpressCompanyViewHolder holder, final int position) {
        if ("1".equals(mBean.get(position).getIsSelected())){
            holder.select.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.open_message));
            holder.select.setVisibility(View.VISIBLE);
        }else{
            holder.select.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.off_message));
            holder.select.setVisibility(View.GONE);
        }
        holder.name.setText(mBean.get(position).getDisName());
        holder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onClick(position);
            }
        });
    }

    @Override
    public ExpressCompanyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View contentView = LayoutInflater.from(mContext).inflate(R.layout.item_express_company,null);
        return new ExpressCompanyViewHolder(contentView);
    }

    @Override
    public int getItemCount() {
        return null == mBean ? 0 : mBean.size();
    }

    class ExpressCompanyViewHolder  extends RecyclerView.ViewHolder{

        LinearLayout layout;
        ImageView select;
        TextView name;

        public ExpressCompanyViewHolder(View view){
            super(view);
            layout = (LinearLayout) view.findViewById(R.id.layout_company);
            select = (ImageView) view.findViewById(R.id.iv_select);
            name = (TextView) view.findViewById(R.id.tv_company_name);
        }
    }

    public interface OnClickListener{
        void onClick(int position);
    }
}
